package com.service.ljl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import com.alibaba.fastjson.JSONObject;
import com.dao.ljl.Deliverdao;
import com.dao.ljl.deliverrecorddao;
import com.entity.Deliver;
import com.entity.Deliverrecord;

@Service
@Transactional(rollbackFor=ServiceException.class)
public class deliverrecordservice {
	@Autowired
	private deliverrecorddao deliverrecorddao;
	@Autowired
	private Deliverdao deliverdao;
	
	public void add(@SuppressWarnings("rawtypes") Map map) {
		Deliverrecord deliverrecord=(Deliverrecord)JSONObject.parseObject(map.get("deliverrecord").toString(),Deliverrecord.class);
		Long id=JSONObject.parseObject(map.get("id").toString(),Long.class);
		deliverrecord.setDeliver(deliverdao.findOne(id));
		deliverrecorddao.save(deliverrecord);
	}
	
//	public Map findall(int pagesize,int currage) {
//		List<Deliverrecord> li=(List<Deliverrecord>) deliverrecorddao.findAll();
//		Map map=new HashMap<>();
//		int start = (currage - 1) * pagesize;
//		int finish = currage * pagesize;
//		if (finish > li.size()) {
//			finish = li.size();
//		}
//		map.put("deliverrecord", li.subList(start, finish));
//		map.put("total", li.size());
//		return map;
//	}
	
	public void delete(Long id) {
		deliverrecorddao.delete(id);
	}
	
	public void deletes(List<Long> ids) {
		for(int i=0;i<ids.size();i++) {
			deliverrecorddao.delete(ids.get(i));
		}
	}

}
